<?php
/**
 * MongoDig
 *
 * @copyright  Copyright (c) 2010 lanyanguang (http://www.lanyg.com)
 * @license    GNU General Public License 2.0
 * @version    $Id$
 */

/** cat逻辑操作 */

//插入一个分类
function cat_insert($cat)
{
	global $db;
	$collection = $db->cat;
	$collection->insert($cat);
}

//批量添加分类
function cat_insert_patch($cats)
{
	global $db;
	$collection = $db->cat;
	$collection->batchInsert($cats);
}

//删除一个分类
function cat_delete($filter)
{
	global $db;
	$collection = $db->cat;
	$collection->remove($filter);
}

//更新一个分类信息
function cat_update($filter,$cat)
{
	global $db;
	$collection = $db->cat;
	$collection->update($filter,$cat);
}

//查找一个分类信息
function cat_find_one($filter)
{
	global $db;
	$collection = $db->cat;
	return $cat = $collection->findOne($filter);
}

//查找分类信息
function cat_find($filter='')
{
	global $db;
	$collection = $db->cat;
	if(empty($filter)){
		return $cat = $collection->find();
	}else{
		return $cat = $collection->find($filter);
	}
}